//
//  ScrollView.m
//  HuiWenMovie
//
//  Created by ios on 15/7/23.
//  Copyright (c) 2015年 ios. All rights reserved.
//

#import "ScrollView.h"
#import "UIImageView+WebCache.h"
@implementation ScrollView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        imageView = [[UIImageView alloc]initWithFrame:self.bounds];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self addSubview:imageView];
        self.delegate = self;
        self.maximumZoomScale = 3;
        self.minimumZoomScale = 1;
        
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap)];
        doubleTap.numberOfTapsRequired = 2;
        [self addGestureRecognizer:doubleTap];
        
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap)];
        
        [singleTap requireGestureRecognizerToFail:doubleTap];
       
        [self addGestureRecognizer:singleTap];
        
    }
    return self;
}

- (void)singleTap
{
    NSLog(@"singleTap");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"HideNavigationBar" object:nil];

}

- (void)doubleTap
{
    NSLog(@"doubleTap");
    if (self.zoomScale == 1)
    {
        [self setZoomScale:3 animated:YES];
    }
    else
    {
        [self setZoomScale:1 animated:YES];
    }

}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return imageView;
}
- (void)setImageUrl:(NSString *)imageUrl
{
    _imageUrl = imageUrl;
    [self setNeedsLayout];
}

- (void)layoutSubviews
{
    [imageView sd_setImageWithURL:[NSURL URLWithString:_imageUrl]];

}

@end
